Trim a value

Hi everyone,
I need to trim the text values I am importing from an Excel file, but I cannot find any trim() function on the DXL manual.
How should I proceed ? Could anyone suggest ?

This is how I get the data from XL : (it works perfectly, but it needs to be 'trimmed')

for(i = 2; i <= totalRows; i++) {
Buffer currentKeyValue = create
currentKeyValue = getCellText(i, objectKeyColumn)
How do I trim the value of currentKeyValue ?
Thanks a million !!!
SystemAdmin - Fri Oct 16 06:46:52 EDT 2009

Re: Trim a value
dpechacek - Fri Oct 16 07:06:05 EDT 2009

Are you wanting a PHP trim like function?
Here's two versions.

string trimWhitespace(string s) {
   int first = 0;
   int last = length(s) - 1;
 
   while(last > 0 && (isspace(s[last]) || s[last] == '\n' || s[last] == '\r' || s[last] == '\t')) {
      last--;
   }
   while(isspace(s[first]) && first < last) {
      first++;
   }
   if(s[first:last] == " ") {
      return("");
   }
   
   return(s[first:last]);
}
 
Buffer trimWhitespace(Buffer b) {
   int frst = 0;
   int lst = length(b) - 1;
 
   while(lst > 0 && (isspace(b[lst]) || b[lst] == '\n' || b[lst] == '\r' || b[lst] == '\t')) {
      lst--;
   }
   while(isspace(b[frst]) && frst < lst) {
      frst++;
   }
   if(tempStringOf(b[frst:lst]) == " ") {
      b = "";
      return(b);
   }
   return(b[frst:lst]);
}

 


AAI Services, Textron
dpechacek@aai.textron.com
David.Pechacek@gmail.com